package pip.can;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.border.EmptyBorder;
import javax.swing.JProgressBar;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ProgressDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private static String title = "Symulacja trwa";
	private ProgressDialog dialog;
	private JButton btnWyniki;
	private JProgressBar progressBar;
	//Timer timer;
	int i;
	final static int interval = 1000;
	/**
	 * Create the dialog.
	 */
	public JButton getResultBtn(){
		return btnWyniki;
	}

	private void showResults(){
		ResultGraph gr = new ResultGraph();
	}
	public JProgressBar getProgressBar(){
		return progressBar;
	}
/*	public void startTimer(){
		timer.start();
	}*/
	public ProgressDialog(JFrame parent) {
		
		super(parent,title, true);
		this.dialog = this;
		setResizable(false);
		setBounds(100, 100, 450, 185);
	    if (parent != null) {
	        Dimension parentSize = parent.getSize(); 
	        Point p = parent.getLocation(); 
	        setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4);
	        
	      }
		
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JButton btnPrzerwij = new JButton("Przerwij");
		btnPrzerwij.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//temp 
				//timer.stop();
				//btnWyniki.setEnabled(true);
				StaticVariables.setEnd(true);
			}
		});
		btnPrzerwij.setBounds(77, 102, 117, 25);
		contentPanel.add(btnPrzerwij);
		
		progressBar = new JProgressBar(0,100);
		progressBar.setBounds(12, 41, 424, 25);
		progressBar.setStringPainted(true);
		contentPanel.add(progressBar);
		
		 btnWyniki = new JButton("Wyniki");
		 btnWyniki.addActionListener(new ActionListener() {
		 	public void actionPerformed(ActionEvent e) {
		 		dialog.dispose();
		 		showResults();
		 	}
		 });
		btnWyniki.setEnabled(false);
		btnWyniki.setBounds(250, 102, 117, 25);
		contentPanel.add(btnWyniki);
		//timer.start();
		
	}
}
